/*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* Alternatively, this software may be distributed under the terms of BSD
* license.
*
*
*
* Authors:                  zhoujian
* Email:            343600434@qq.com
* Date:         Feb-18-2024 16:33:22
*
*/


#ifndef __ds3231_H__
#define __ds3231_H__




#ifdef __cplusplus
extern "C" {
#endif

//#define ENGLISH_VERSION
//#define ITALIAN_VERSION
#define ESPANOL_VERSION




typedef enum {
    DS3231_State_0x00 = 0x00,
    DS3231_State_0x01 = 0x01,
    DS3231_State_0x02 = 0x02,
    DS3231_State_0x03 = 0x03,
} DS3231_zTypeDef;


extern DS3231_zTypeDef ds3231_state;


void ds3231_init(void);
void ds3231_task(void);
void ds3231_deinit(void);
void ds3231_read_test(void);


#define IS_I2C_SDA_H (GPIO_ISTAT(GPIOC) & (GPIO_PIN_7))
#define I2C_SDA_INPUT do{gpio_mode_set(GPIOC, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, GPIO_PIN_7);}while(0)
#define I2C_SDA_OUTPUT do{/*rcu_periph_clock_enable(RCU_GPIOC);*/gpio_mode_set(GPIOC, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN_7);}while(0)

//#define I2C_D_H gpio_bit_set(GPIOC, GPIO_PIN_7)
#define I2C_SDA_H do{GPIO_BOP(GPIOB) = (uint32_t)GPIO_PIN_12;}while(0)


//#define I2C_D_L gpio_bit_reset(GPIOC, GPIO_PIN_7)
#define I2C_SDA_L do{GPIO_BC(GPIOB) = (uint32_t)GPIO_PIN_12;}while(0)
//#define I2C_C_H gpio_bit_set(GPIOC, GPIO_PIN_6)
#define I2C_SCL_H  do{GPIO_BOP(GPIOB) = (uint32_t)GPIO_PIN_11;}while(0)
//#define I2C_C_L gpio_bit_reset(GPIOC, GPIO_PIN_6)
#define I2C_SCL_L do{GPIO_BC(GPIOB) = (uint32_t)GPIO_PIN_11;}while(0)

typedef struct CALENDAR {
    uint8_t w_year;
    uint8_t w_month;
    uint8_t w_date;
    uint8_t hour;
    uint8_t min;
    uint8_t sec;
}

DS3231_CALENDAR_T;
extern DS3231_CALENDAR_T calendar;
void ds3231_get_2min_start();
uint8_t ds3231_is_2min_end();
extern volatile uint8_t show_time_update;
extern volatile uint8_t time_end;
extern volatile uint8_t no_rtc;

#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
class ds3231
{

public:
    ds3231();
    ~ds3231();

};
#endif



#endif
